CSC 180 Intelligent Systems (Spring 2021)

Dr. Haiquan Chen, Dept of Computer Scicence

California State University, Sacramento

Lab 11 Multi-output Regression and Auto-encoder

Helpful Functions for Tensorflow (Little Gems)

The following functions will be used with TensorFlow to help preprocess the data. They allow you to build the feature vector for a neural network.

Multi-Output Regression

Unlike most models, neural networks can provide multiple regression outputs. This allows a neural network to generate multiple outputs for the same input.

The following program uses a multi-output regression to predict both sin and cos from the same input data.

Simple Auto Encoder

An auto encoder is a neural network that has the same number of input neurons as output neurons.

The hidden layers of the neural network will have fewer neurons than the input/output neurons. Because there are fewer neurons, the auto-encoder must learn to encode the input to the fewer hidden neurons. The predictors (x) and output (y) are exactly the same in an auto encoder. Because of this, auto encoders are said to be unsupervised.

Simple Auto Encoder

The following program demonstrates an auto encoder that learns to encode an image.

Reading Images in Python using Pillow

https://pillow.readthedocs.io/en/stable/index.html

The following code uses Pillow to load and display an image in RGB color model.

Creating Images at pixel level

Pillow can also be used to create an image from a 3D numpy cube. The rows and columns specify the pixels. The depth, of 3, specifies red, green and blue. Here a simple image is created.

Transform Images at the pixel level

We can combine the last two programs and modify images. Here we take the mean color of each pixel and form a grayscale image.

Demo about using auto encoders to handle noise

Adding Noise to an Image

Auto encoders can handle noise. First it is important to see how to add noise to an image. There are many ways to add such noise. The following code adds random black squares to the image to produce noise.

Denoising Autoencoder

A denoising auto encoder is designed to remove noise from input signals.

To do this the $y$ becomes each image while the $x$ becomes a version of $y$ with noise added.

https://pillow.readthedocs.io/en/3.1.x/reference/Image.html

We create 10 noisy versions of each image. The network is trained to convert noisy data ($x$) to the origional input ($y$).

Why (50, 196608)?